package com.models;


import java.util.List;

import com.om.base.DateTimeDisplay;
import com.om.base.Field;
import com.om.base.Many2one;
import com.om.base.One2many;
import com.om.base.PrimaryKey;
import com.om.base.Entity;
import com.om.common.BaseBean;

@SuppressWarnings("serial")
@Entity(tableName = "tb_goods_category") //模型对应表名称
@PrimaryKey(name = "id")               //表主键配置
public class GoodsCategory extends BaseBean {
	
	//配置主从结构
	@One2many(childClass = GoodsPrice.class, parentColumn = "id", childColumn = "goods_id", autoLoad = true)
	public List<GoodsPrice> priceList;
	
	//配置外键关联数据
	@Many2one(localColumn="brand_id",foreignColumn="id",forignClass=Brand.class,autoLoad=true)
	public List<Brand> brandList;
	
	//配置非空、唯一、不可编辑字段
	@Field(name = "code", required = true, unique = true, readOnly = true)
	public String code;
	
	//价格字段声明为非空项
	@Field(name = "price", required = true)
	public Object  price;
		
	//格式化制定的日期字段
	@DateTimeDisplay(field = "create_time",targetFormat="MM/dd/yyyy")
	public Object createTime;
	
	
	
	//重载默认的生成查询sql的方法实现多表查询(默认为select xxx,xxx... from tb_goods_category)
	@Override
	public String generateQuerySql() {
		return "select a.*,b.name as brand,c.name as model,d.name as unit, concat(a.code,' ',b.name) as display_name from tb_goods_category a "
				+ " left join tb_brand b on a.brand_id=b.id "
				+ " left join tb_type c on a.type_id=c.id  "
				+ " left join tb_unit d on a.unit_id=d.id  ";
	}
	
	//重载基类删除方法
	@Override
	public boolean save() throws Exception{
		return super.save();
	}
	
	//重载基类删除方法
	@Override
	public void deleteItem() throws Exception{
		super.deleteItem();
	}

}
